/**
 * Created by E002871 on 2/10/14.
 */


/* Get unique array */
var unique = function(origArr, attribute) {
    var newArr = [],
        origLen = origArr.length,
        found, x, y;

    for (x = 0; x < origLen; x++) {
        found = undefined;
        for (y = 0; y < newArr.length; y++) {
            if (origArr[x][attribute] === newArr[y][attribute]) {
                found = true;
                break;
            }
        }
        if (!found) {
            newArr.push(origArr[x]);
        }
    }
    return newArr;
}

/* Get Value from Object */
function getValueFromObject(object, property) {
    if(object.hasOwnProperty(property))
    {
        return object[property];
    }
    else
        return '';
}


function generateReportVariableParam(query, org, year, quarter) {
    var result = {};
    var counter = 1;
    var tmp = {};
    if(quarter != '')
    {
      tmp['VAR_NAME_' + counter] = 'ZCOQUAR2';
      tmp['VAR_VALUE_EXT_' + counter] = quarter;
      counter++;
    }

    if(org != "")
    {
        tmp['VAR_NAME_' + counter] = 'ZEHORGH';
        tmp['VAR_VALUE_EXT_' + counter] = org;
        tmp['VAR_NODE_IOBJNM_' + counter] = '';
        counter++;
    }

    if(year != '')
    {
        tmp['VAR_NAME_' + counter] = 'ZEH_FI_YEAR';
        tmp['VAR_VALUE_EXT_' + counter] = year;
    }

    result['variables'] = tmp;
    result['query'] = query;
    result['display_key'] = 'X';
    result['title_grouping'] = 'X';


    return result;
}

